package org.kzwl.book.controller.app;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.kzwl.comm.pojo.ResponseData;
import org.kzwl.comm.pojo.bo.book.BookQueryBasic;
import org.kzwl.comm.pojo.bo.book.BooksBasicBO;
import org.kzwl.comm.pojo.bo.book.QueryTitleBO;
import org.kzwl.comm.pojo.bo.category.CategoryBasic;
import org.kzwl.comm.pojo.dto.book.BookDTO;
import org.kzwl.comm.pojo.dto.book.BookDetailsDTO;
import org.kzwl.comm.pojo.dto.book.HotOrNewDTO;
import org.kzwl.comm.pojo.dto.book.MyBooksDTO;
import org.kzwl.entity.app.Book;
import org.kzwl.entity.app.Category;
import org.kzwl.service.app.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 张国伟/郭家恒
 * @since 2020-09-10
 */
@RestController
@RequestMapping("/book")
@Api("图书")
public class BookController {

    @Autowired
    BookService bookService;


    @GetMapping("/saveTest")
    public ResponseData<Void> saveTest() {
        return bookService.saveTest();
    }

    @GetMapping("/")
    public String test() {
        return "-----------------";
    }

//    @ApiOperation(value = "基础查询")
//    @PostMapping("/queryBasic")
//    public ResponseData<List<Category>> queryBasic(@RequestBody CategoryBasic bo) {
//        List<Category> list = categoryService.queryBasic(bo);
//        return new ResponseData<>();
//    }

    @ApiOperation(value = "编辑推荐")
    @PostMapping("/recommend")
    public ResponseData<List<Book>> recommend() {
        List<Book> list = bookService.recommend();
        return new ResponseData<>(list);
    }

    @ApiOperation(value = "热门榜单")
    @PostMapping("/hot")
    public ResponseData<List<BookDTO>> hotOrNew() {
        HotOrNewDTO list = bookService.hotOrNew();
        return new ResponseData<>(list.getHotList());
    }

    @ApiOperation(value = "每日新书")
    @PostMapping("/NewBooks")
    public ResponseData<List<BookDTO>> NewBooks() {
        HotOrNewDTO list = bookService.NewBooks();
        return new ResponseData<>(list.getNewList());
    }

    @ApiOperation(value = "根据分类查询书籍",notes = "cuBookCategoryId(分类编号)--必填 current(当前页数)--必填 size(每页多少条)--选填")
    @PostMapping("/queryBookByType")
    public ResponseData<List<BookDTO>> queryBookByType(@RequestBody BookQueryBasic bo) {
        IPage<BookDTO> bookDTOIPage = bookService.queryBookByType(bo);
        return new ResponseData<>(bookDTOIPage.getRecords());
    }

    @ApiOperation(value = "查询书籍详情",notes = "cuUserId(用户编号)--必填 cuBookId(图书编号)--必填")
    @PostMapping("/getBook")
    public ResponseData<BookDetailsDTO> getBook(@RequestBody BookQueryBasic bo) {
        BookDetailsDTO dto = bookService.getBook(bo);
        return new ResponseData<>(dto);
    }

    @ApiOperation(value = "热门搜索")
    @PostMapping("/getHot")
    public ResponseData<List<BookDTO>> getHot() {
        List<BookDTO> dto = bookService.getHot();
        return new ResponseData<>(dto);
    }

    @ApiOperation(value = "关键搜索")
    @PostMapping("/queryTitle")
    public ResponseData<List<BookDTO>> queryTitle(@RequestBody QueryTitleBO bo) {
        List<BookDTO> dto = bookService.queryTitle(bo);
        return new ResponseData<>(dto);
    }

//    @PostMapping("/syncBook")
//    public ResponseData<Void> syncBook() {
//        bookService.syncBook();
//        return new ResponseData<>();
//    }

}
